#include "comm.hpp"

int main()
{
    key_t k = getKey();
    printf("key:0x%x\n", k);
    int shmid = getshm(k);
    printf("shmid:%d\n", shmid);

    //sleep(5);

    char *start = (char*)attachShm(shmid);
    printf("attach success, address start: %p\n", start);

    //通信
    const char* message = "hello server,我是另一个进程，正在与你进行通信";
    pid_t id = getpid();
    int cnt = 1;
    while(true)
    {
        sleep(1);
        // snprintf函数直接往start当中写入数据
        snprintf(start,MAX_SIZE,"%s[pid:%d][消息编号：%d]",message,id,cnt++);
    }

    //sleep(5);

    detachShm(start);

    return 0;
} 
